package cn.xunjie.org.controller;

import cn.xunjie.basic.util.AjaxResult;
import cn.xunjie.basic.util.PageList;
import cn.xunjie.org.domain.Dictionarydetail;
import cn.xunjie.org.query.DictionarydetailQuery;
import cn.xunjie.org.service.IDictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionarydetail")

public class DictionarydetailController {
    @Autowired
    private IDictionarydetailService dictionarydetailService;
    @GetMapping("/{id}")
    public Dictionarydetail querById(@PathVariable("id") Long id){
        return dictionarydetailService.queryById(id);
    }
    @GetMapping
    public List<Dictionarydetail> queryAll(){
        return dictionarydetailService.queryAll();
    }
    //高级查询+分页
    @PostMapping
    public PageList<Dictionarydetail> queryPage(@RequestBody DictionarydetailQuery query){
        return dictionarydetailService.queryPage(query);
    }
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Dictionarydetail dictionarydetail){
            try {
                if (dictionarydetail.getId()==null){
                    dictionarydetailService.save(dictionarydetail);
                }else {
                    dictionarydetailService.update(dictionarydetail);
                }
                return AjaxResult.me();
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("瓦了");
            }
    }
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id")Long id){
        try {
            dictionarydetailService.removeById(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("瓦了");
        }
    }
    @PatchMapping
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {
            dictionarydetailService.batchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("瓦了");
        }
    }

}
